package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.lianzhihui.romeex.bean.WalletMainBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.lianzhihui.romeex.utils.LogUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

/**
 * Description:
 * Author: RAMON
 * CreateDate: 2020/11/9 10:23 AM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class WalletInfoModelImp {

    Context context;
    WalletInfoInterface callback;

    public WalletInfoModelImp(Context context, WalletInfoInterface callback) {
        this.context = context;
        this.callback = callback;
    }

    /**
     * 获取钱包主页信息
     */
    public void getWalletInfo() {

        HttpParams params = new HttpParams();
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                LogUtil.info("walletInfo:", o.getCode() + "");
                if (o.getCode() == 200) {
                    WalletMainBean bean = GsonUtil.GsonToBean(o.getData(),WalletMainBean.class);
                    callback.onGetWalletInfo(bean);
                } else {
                    callback.onGetWalletInfoFail(o.getCode());
                }
            }

            @Override
            public void onError(ApiException e) {
                callback.onGetWalletInfoFail(e.getMessage());
            }
        }).post(APIConstant.WALLET_INFO, params);

    }

}
